<?php


namespace app\admin\controller\Free;


use app\admin\controller\AppController;
use app\admin\model\Free\FreeOrderModel;
use app\Request;
use app\Utils\Util;

class FreeGoods extends AppController
{
    /**
     * 分页查询
     * @param Request $request
     * @return array
     */
    public function getFreeGoodsList(Request $request)
    {
        $param = $request->param();
        $where = [];
        $page = !empty($param['page']) ? $param['page'] : 1;
        $limit = !empty($param['limit']) ? $param['limit'] :10;
        if (!empty($param['keyword'])) {
            array_push($where, ['order_sn', 'like', '%' . $param['keyword'] . '%']);
        }
        if (!isset($param['status'])) {
            array_push($where, ['status', '=', $param['status']]);
        }
        $list = FreeOrderModel::getFreeOrderListWhere($page, $limit, $where);
        $count = FreeOrderModel::getFreeOrderCountWhere($where);
        foreach ($list as &$item){
            $item['goods_info'] = json_decode($item['goods_info'],true);
        }
        return Util::returnPageJson(self::CODE_DATA, $count, $list, "");
    }
}